package com.th.supcom.pds.phamapply.client.widget.phamdispense;

import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.GridEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.th.supcom.pds.phamapply.client.model.InpPhamDispenseDetailModel;

/**
 * 住院摆药事件监听
 * 
 * @author 杨冲
 */
public class PhamDispenseListener
{
    private PhamDispenseButtons m_phamDispenseButtons;
    private PhamDispenseAction m_phamDispenseAction;
    private PhamDispenseFields m_phamDispenseFields;
    private PhamDispenseNurseUnitInfoGrid m_dispenseNurseUnitInfoGrid;

    /**
     * 设置药品请领按钮组件
     * 
     * @param phamDispenseButtons
     */
    public void setPhamDispenseButtons (PhamDispenseButtons phamDispenseButtons)
    {

        this.m_phamDispenseButtons = phamDispenseButtons;
    }

    /**
     * 设置药品请领事件
     * 
     * @param phamDispenseAction
     */
    public void setPhamDispenseAction (PhamDispenseAction phamDispenseAction)
    {

        this.m_phamDispenseAction = phamDispenseAction;
    }

    /**
     * 设置药品请领文本组件
     * 
     * @param phamapplyFields
     */
    public void setPhamDispenseFields (PhamDispenseFields phamDispenseFields)
    {

        this.m_phamDispenseFields = phamDispenseFields;
    }

    /**
     * 设置护理单元Grid
     * 
     * @param dispenseNurseUnitInfoGrid
     */
    public void setDispenseNurseUnitInfoGrid (PhamDispenseNurseUnitInfoGrid dispenseNurseUnitInfoGrid)
    {

        m_dispenseNurseUnitInfoGrid = dispenseNurseUnitInfoGrid;
    }

    /**
     * 初始化所有的Listener
     */
    public void initListeners ()
    {
        addPhamDispenseListener ();
        addQueryDispenseListener ();
    }

    /**
     * 设置摆药事件监听
     */
    public void addPhamDispenseListener ()
    {
        m_phamDispenseButtons.getDispenseButton ().addSelectionListener (new SelectionListener <ButtonEvent> ()
        {

            @Override
            public void componentSelected (ButtonEvent ce)
            {
                openOperateRecordWindow ();
            }
        });

    }

    /**
     * 打开员工操作记录窗口
     */
    public void openOperateRecordWindow ()
    {
        PhamDispenseOperateRecordWindow window = new PhamDispenseOperateRecordWindow ();
        window.setPhamDispenseButtons (m_phamDispenseButtons);
        window.setPhamDispenseFields (m_phamDispenseFields);
        window.setDispenseAction (m_phamDispenseAction);
        window.initUI ();
        window.show ();
    }

    /**
     * 设置查询摆药明细事件
     */
    public void addQueryDispenseListener ()
    {
        m_dispenseNurseUnitInfoGrid.getGrid ().addListener (Events.CellClick, new Listener <GridEvent <InpPhamDispenseDetailModel>> ()
        {

            @Override
            public void handleEvent (GridEvent <InpPhamDispenseDetailModel> be)
            {
                m_phamDispenseAction.getDispenseDetail ();
            }
        });

    }

}
